package com.ruoyi.web.controller.train;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.framework.web.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TrainingCadetRotationPlan;
import com.ruoyi.system.service.ITrainingCadetRotationPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培训对象科室轮转计划Controller
 * 
 * @author dp
 * @date 2023-11-27
 */
@Api(tags={"培训对象科室轮转计划"})
@RestController
@RequestMapping("/train/plan")
public class TrainingCadetRotationPlanController extends BaseController
{
    @Autowired
    private ITrainingCadetRotationPlanService trainingCadetRotationPlanService;
    @Autowired
    TokenService tokenService;

    /**
     * 查询培训对象科室轮转计划列表
     */
    @ApiOperation(value = "培训对象科室轮转计划列表", notes = "查询培训对象科室轮转计划列表详情", tags = {"培训对象科室轮转计划管理"})
    //@PreAuthorize("@ss.hasPermi('train:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainingCadetRotationPlan trainingCadetRotationPlan)
    {
        startPage();
        List<TrainingCadetRotationPlan> list = trainingCadetRotationPlanService.selectTrainingCadetRotationPlanList(trainingCadetRotationPlan);
        return getDataTable(list);
    }

    /**
     * 导出培训对象科室轮转计划列表
     */
    @ApiOperation(value = "培训对象科室轮转计划列表导出", notes = "导出培训对象科室轮转计划列表", tags = {"培训对象科室轮转计划管理"})
    //@PreAuthorize("@ss.hasPermi('train:plan:export')")
    @Log(title = "培训对象科室轮转计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainingCadetRotationPlan trainingCadetRotationPlan)
    {
        List<TrainingCadetRotationPlan> list = trainingCadetRotationPlanService.selectTrainingCadetRotationPlanList(trainingCadetRotationPlan);
        ExcelUtil<TrainingCadetRotationPlan> util = new ExcelUtil<TrainingCadetRotationPlan>(TrainingCadetRotationPlan.class);
        util.exportExcel(response, list, "培训对象科室轮转计划数据");
    }

    /**
     * 获取培训对象科室轮转计划详细信息
     */
    @ApiOperation(value = "培训对象科室轮转计划详细信息", notes = "获取培训对象科室轮转计划详细信息详情", tags = {"培训对象科室轮转计划管理"})
    //@PreAuthorize("@ss.hasPermi('train:plan:query')")
    @GetMapping(value = "/{rotationPlanId}")
    public AjaxResult getInfo(@PathVariable("rotationPlanId") Long rotationPlanId)
    {
        return success(trainingCadetRotationPlanService.selectTrainingCadetRotationPlanByRotationPlanId(rotationPlanId));
    }

    /**
     * 新增培训对象科室轮转计划
     */
    @ApiOperation(value = "新增培训对象科室轮转计划", notes = "新增培训对象科室轮转计划详情", tags = {"培训对象科室轮转计划管理"})
    //@PreAuthorize("@ss.hasPermi('train:plan:add')")
    @Log(title = "培训对象科室轮转计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(HttpServletRequest request, @RequestBody TrainingCadetRotationPlan trainingCadetRotationPlan)
    {
        Long userId = tokenService.getLoginUser(request).getUser().getUserId();
        trainingCadetRotationPlanService.completeData(trainingCadetRotationPlan, userId, 1);
        return toAjax(trainingCadetRotationPlanService.insertTrainingCadetRotationPlan(trainingCadetRotationPlan));
    }

    /**
     * 修改培训对象科室轮转计划
     */
    @ApiOperation(value = "修改培训对象科室轮转计划", notes = "修改培训对象科室轮转计划详情", tags = {"培训对象科室轮转计划管理"})
    //@PreAuthorize("@ss.hasPermi('train:plan:edit')")
    @Log(title = "培训对象科室轮转计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(HttpServletRequest request, @RequestBody TrainingCadetRotationPlan trainingCadetRotationPlan)
    {
        Long userId = tokenService.getLoginUser(request).getUser().getUserId();
        trainingCadetRotationPlanService.completeData(trainingCadetRotationPlan, userId, 2);
        return toAjax(trainingCadetRotationPlanService.updateTrainingCadetRotationPlan(trainingCadetRotationPlan));
    }

    /**
     * 删除培训对象科室轮转计划
     */
    @ApiOperation(value = "删除培训对象科室轮转计划", notes = "删除培训对象科室轮转计划详情", tags = {"培训对象科室轮转计划管理"})
    //@PreAuthorize("@ss.hasPermi('train:plan:remove')")
    @Log(title = "培训对象科室轮转计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rotationPlanIds}")
    public AjaxResult remove(@PathVariable Long[] rotationPlanIds)
    {
        return toAjax(trainingCadetRotationPlanService.deleteTrainingCadetRotationPlanByRotationPlanIds(rotationPlanIds));
    }
}
